<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('类目列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
<!--                            <li>-->
<!--                                <p>类目：</p>-->
<!--                                <select name="categoryType" th:with="type=${@dict.getType('')}">-->
<!--                                    <option value="">所有</option>-->
<!--                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
<!--                                </select>-->
<!--                            </li>-->
                            <li>
                                <p>类目名称：</p>
                                <input type="text" name="categoryName"/>
                            </li>
<!--                            <li>-->
<!--                                <p>就餐开始时间：</p>-->
<!--                                <input type="text" name="repastStarttime"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <p>就餐结束时间：</p>-->
<!--                                <input type="text" name="repastEndtime"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <p>就餐金额：</p>-->
<!--                                <input type="text" name="repastMoney"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <p>预留字段2：</p>-->
<!--                                <input type="text" name="back2"/>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="wechatprogram:wxCategory:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wechatprogram:wxCategory:edit')}]];
        var categoryStatusDatas = [[${@dict.getType('category_status')}]];
        var editmenuFlag = [[${@permission.hasPermi('wechatprogram:wxCategory:editmenu')}]];
        var removeFlag = [[${@permission.hasPermi('wechatprogram:wxCategory:remove')}]];
        var publishCategoryStatusFlag = [[${@permission.hasPermi('wechatprogram:wxCategory:publish')}]];
        var unpublishCategoryStatusFlag = [[${@permission.hasPermi('wechatprogram:wxCategory:unpublish')}]];

        var prefix = ctx + "wechatprogram/wxCategory";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                updatemenuUrl: prefix + "/editmenu/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "类目",
                modalMenuName: "菜品",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '主键',
                    visible: false
                },
                // {
                //     field : 'categoryType',
                //     title : '类目'
                // },
                {
                    field : 'categoryName', 
                    title : '类目名称'
                },
                {
                    field : 'starttime',
                    title : '就餐开始时间'
                },
                {
                    field : 'endtime',
                    title : '就餐结束时间'
                },
                {
                    field : 'repastMoney',
                    title : '就餐金额'
                },
                {
                    field : 'categoryStatus',
                    title : '商品状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(categoryStatusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(0 == row.categoryStatus){
                            actions.push('<a class="btn btn-primary btn-xs ' + publishCategoryStatusFlag + '" href="javascript:void(0)" onclick="publish(\'' + row.id +'\',\''+ row.categoryName +  '\')"><i class="fa fa-edit"></i>显示</a> ');
                        }
                        if(1 == row.categoryStatus){
                            actions.push('<a class="btn btn-danger btn-xs ' + unpublishCategoryStatusFlag + '" href="javascript:void(0)" onclick="unpublish(\'' + row.id +'\',\''+ row.categoryName + '\')"><i class="fa fa-edit"></i>隐藏</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + editmenuFlag + '" href="javascript:void(0)" onclick="$.operate.editmenu(\'' + row.id + '\')"><i class="fa fa-edit"></i>绑定餐品</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        function publish(id,menuName) {
            $.modal.confirm("确定显示：" + menuName + "吗？", function () {
                var url = prefix + "/publishCategory/" + id;
                $.operate.submit(url, "post");
            });
        }

        function unpublish(id,menuName) {
            $.modal.confirm("确定隐藏：" + menuName + "吗？", function () {
                var url = prefix + "/unPublishCategory/" + id;
                $.operate.submit(url, "post");
            });
        }



    </script>
</body>
</html>